home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 February: Tool Chest / Dev.CD Feb 99 TC.toast / What's New? / Development Kits / Mac OS USB v1.1f3 DDK / Examples / CompositeClassDriver / CompositeDriverDescription.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-07  |  6.5 KB  |  208 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        CompositeDriverDescription.c
  3.  
  4.     Contains:    Composite Class Driver Definition Header
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.     Copyright:    © 1997-1998 by Apple Computer, Inc., all rights reserved.
  9.  
  10. */
  11.  
  12. #include <Types.h>
  13. #include <Devices.h>
  14. #include <DriverServices.h>
  15. #include <USB.h>
  16.  
  17.  
  18. #include "CompositeClassDriver.h"
  19. #include "CompositeClassVersion.h"
  20.  
  21. usbCompositePBStruct newInterfacesPB;
  22.  
  23.  
  24. OSStatus CompositeDriverInitInterface(
  25.             UInt32                         interfaceNum, 
  26.             USBInterfaceDescriptor        *interfaceDesc, 
  27.             USBDeviceDescriptor            *deviceDesc, 
  28.             USBDeviceRef                 device);
  29.  
  30. //------------------------------------------------------
  31. //
  32. //    This is the driver description structure that the expert looks for first.
  33. //  If it's here, the information within is used to match the driver
  34. //  to the device whose descriptor was passed to the expert.
  35. //    Information in this block is also used by the expert when an
  36. //  entry is created in the Name Registry.
  37. //
  38. //------------------------------------------------------
  39. USBDriverDescription    TheUSBDriverDescription = 
  40. {
  41.     // Signature info
  42.     kTheUSBDriverDescriptionSignature,
  43.     kInitialUSBDriverDescriptor,
  44.     
  45.     // Device Info
  46.     0,                                        // vendor = not device specific
  47.     0,                                        // product = not device specific
  48.     0,                                        // version of product = not device specific
  49.     0,                                        // protocol = not device specific
  50.     
  51.     // Interface Info    (* I don't think this would always be required...*)                
  52.     0,                                        // Configuration Value
  53.     0,                                        // Interface Number
  54.     0,                                        // Interface Class
  55.     0,                                         // Interface SubClass
  56.     0,                                        // Interface Protocol
  57.         
  58.     
  59.     // Driver Info
  60.     "\pUSBCompositeDevice",                    // Driver name for Name Registry
  61.     kUSBCompositeClass,                        // Device Class  (from USBDeviceDefines.h)
  62.     kUSBCompositeSubClass,                    // Device Subclass 
  63.     kCMPHexMajorVers, 
  64.     kCMPHexMinorVers, 
  65.     kCMPCurrentRelease, 
  66.     kCMPReleaseStage,                        // version of driver
  67.     
  68.     // Driver Loading Info
  69.     kUSBDoNotMatchInterface                    // Please don't load us as an interface driver.
  70. };
  71.  
  72. USBClassDriverPluginDispatchTable TheClassDriverPluginDispatchTable =
  73. {
  74.     kClassDriverPluginVersion,                // Version of this structure
  75.     CompositeDriverValidateHW,                // Hardware Validation Procedure
  76.     CompositeDriverInitialize,                // Initialization Procedure
  77.     CompositeDriverInitInterface,            // Interface Initialization Procedure
  78.     CompositeDriverFinalize,                    // Finalization Procedure
  79.     CompositeDriverNotifyProc                // Driver Notification Procedure
  80. };
  81.  
  82. // hubDriverInitInterface function
  83. // Called to initialize driver for an individual interface - either by expert or
  84. // internally by driver
  85. OSStatus CompositeDriverInitInterface(
  86.             UInt32                         interfaceNum, 
  87.             USBInterfaceDescriptor        *interfaceDesc, 
  88.             USBDeviceDescriptor            *deviceDesc, 
  89.             USBDeviceRef                 device)
  90. {
  91. #pragma unused (interfaceNum)
  92. #pragma unused (interfaceDesc)
  93. #pragma unused (deviceDesc)
  94. #pragma unused (device)
  95.  
  96.     return (OSStatus)kUSBNoErr;
  97. }
  98.  
  99. OSStatus    CompositeDriverNotifyProc(UInt32     notification, void *pointer, UInt32 refcon)
  100. {
  101. #pragma unused (pointer)
  102. #pragma unused (notification)
  103. #pragma unused (refcon)
  104.     return(kUSBNoErr);
  105. }
  106.  
  107. // Hardware Validation
  108. // Called upon load by Expert
  109. OSStatus CompositeDriverValidateHW(USBDeviceRef device, USBDeviceDescriptor *desc)
  110. {
  111. #pragma unused (device)
  112. #pragma unused (desc)
  113.  
  114.     return (OSStatus)kUSBNoErr;
  115. }
  116.  
  117. // Initialization function
  118. // Called upon load by Expert
  119. OSStatus     CompositeDriverInitialize (USBDeviceRef device, USBDeviceDescriptorPtr pDesc,  UInt32 busPowerAvailable)
  120. {
  121. #pragma unused (busPowerAvailable)
  122.  
  123.     // until we get going, it's okay to accept a call to finalize
  124.     newInterfacesPB.okayToFinalizeFlag = true;
  125.     DeviceInitialize(device, pDesc, busPowerAvailable);
  126.     return (OSStatus)kUSBNoErr;
  127. }
  128.  
  129. // Termination function
  130. // Called by Expert when driver is being shut down
  131. OSStatus CompositeDriverFinalize(USBDeviceRef theDeviceRef, USBDeviceDescriptorPtr pDesc)
  132. {
  133. #pragma unused (pDesc)
  134. UInt32 i;
  135. OSStatus myErr;
  136.  
  137.     // If all the interfaces have been examined and had their interface
  138.     // drivers loaded, then go ahead and removed them all
  139.     // otherwise just return with a device busy error code.
  140.     USBExpertStatus(newInterfacesPB.pb.usbReference, "\pComposite Driver: Finalize", newInterfacesPB.pb.usbStatus);
  141.     if (theDeviceRef == newInterfacesPB.deviceRef)
  142.     {
  143.         if (newInterfacesPB.okayToFinalizeFlag)
  144.         {
  145.             USBExpertStatus(newInterfacesPB.pb.usbReference, "\pComposite Driver: Removing Interface drivers & InterfaceRefs", newInterfacesPB.pb.usbStatus);
  146.             for (i=0; i < newInterfacesPB.interfaceCount; i++)
  147.             {
  148.                 USBExpertRemoveInterfaceDriver(newInterfacesPB.interfaceRefArray[i]);
  149.                 InitParamBlock(newInterfacesPB.interfaceRefArray[i], &newInterfacesPB.pb);
  150.                 newInterfacesPB.pb.usbRefcon = 0;             
  151.                 newInterfacesPB.pb.usb.cntl.WIndex = i;
  152.                 newInterfacesPB.pb.usbCompletion = (USBCompletion)-1;
  153.                 myErr = USBDisposeInterfaceRef(&newInterfacesPB.pb);
  154.                 if(immediateError(myErr))
  155.                 {
  156.                     USBExpertFatalError(newInterfacesPB.interfaceRefArray[i], kUSBInternalErr, "\pComposite Driver: USBDisposeInterfaceRef - immediate error", myErr);
  157.                 }
  158.             }
  159.             
  160.             InitParamBlock(newInterfacesPB.deviceRef, &newInterfacesPB.pb);
  161.             newInterfacesPB.pb.usbRefcon = 0;             
  162.             newInterfacesPB.pb.usbBuffer = newInterfacesPB.pFullConfigDescriptor;        
  163.             newInterfacesPB.pb.usbCompletion = (USBCompletion)-1;
  164.             myErr = USBDeallocMem(&newInterfacesPB.pb);
  165.             return (OSStatus)kUSBNoErr;
  166.         }
  167.         else
  168.         {
  169.             return (OSStatus)kUSBDeviceBusy;
  170.         }
  171.     }
  172.     else
  173.     {
  174.         USBExpertFatalError(newInterfacesPB.pb.usbReference, kUSBInternalErr, "\pComposite Driver - Finalize received unknown deviceRef", newInterfacesPB.pb.usbRefcon);
  175.         return (OSStatus)kUSBUnknownDeviceErr;
  176.     }
  177. }
  178.  
  179. void DeviceInitialize(USBDeviceRef device, USBDeviceDescriptorPtr pDeviceDescriptor, UInt32 busPowerAvailable)
  180. {
  181. static Boolean beenThereDoneThat = false;
  182.  
  183.     if(beenThereDoneThat)
  184.     {
  185.         USBExpertFatalError(device, kUSBInternalErr, "\pComposite driver is not reentrant!", 0);
  186.         return;
  187.     }
  188.     beenThereDoneThat = true;
  189.     newInterfacesPB.okayToFinalizeFlag = false;
  190.     
  191.     newInterfacesPB.deviceRef = device;    
  192.     newInterfacesPB.deviceDescriptor = *pDeviceDescriptor;    
  193.     
  194.     newInterfacesPB.busPowerAvailable = busPowerAvailable;                            
  195.     newInterfacesPB.delayLevel = 0;                            
  196.     newInterfacesPB.transDepth = 0;                            
  197.     newInterfacesPB.retryCount = kCompositeRetryCount;
  198.     newInterfacesPB.pFullConfigDescriptor = nil;
  199.     
  200.     InitParamBlock(device, &newInterfacesPB.pb);
  201.     newInterfacesPB.pb.usbRefcon = kGetFullConfiguration0;            /* Start out at first state */
  202.     
  203. //    DebugStr("\pIn Composite Driver");
  204.     CompositeDeviceInitiateTransaction(&newInterfacesPB.pb);
  205. }
  206.  
  207.  
  208.